Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@emotion/cache
Advanced tools
The @emotion/cache package is part of the Emotion library, a powerful tool for writing css styles with JavaScript. It is specifically designed to create custom instances of Emotion's cache, which can be useful for configuring how styles are processed, inserted, and optimized. This can be particularly beneficial in environments with specific styling needs or when integrating with complex applications.
Custom Cache Creation
This feature allows the creation of a custom cache with a specified key prefix. This is useful for isolating styles in large applications or when using multiple emotion instances on the same page.
import createCache from '@emotion/cache';
const myCache = createCache({ key: 'my-prefix' });
Configuring Cache Options
This feature enables the configuration of the cache with specific options like stylis plugins and whether to prepend the styles. It allows for fine-tuning how styles are processed and inserted into the DOM.
import createCache from '@emotion/cache';
const myCache = createCache({
key: 'custom',
stylisPlugins: [],
prepend: true
});
Styled-components is another CSS-in-JS library that allows you to use tagged template literals to style your components. It creates scoped styles without the need for manual cache management, which differs from @emotion/cache where you can configure and manage your own cache.
JSS (JavaScript Style Sheets) is a CSS-in-JS library that allows for similar customization and optimization of style sheets. JSS provides a more extensive API for managing rules and stylesheets programmatically, which can be seen as more flexible compared to the focused cache management approach of @emotion/cache.
createCache
allows for low level customization of how styles get inserted by emotion. It's intended to be used with the <CacheProvider/>
component to override the default cache, which is created with sensible defaults for most applications.
import createCache from '@emotion/cache'
export const myCache = createCache({
key: 'my-prefix-key',
stylisPlugins: [
/* your plugins here */
]
})
Using emotion in embedded contexts such as an <iframe/>
Setting a nonce on any <style/>
tag emotion creates for security purposes
Using emotion with a developer defined <style/>
tag
Using emotion with custom Stylis plugins
nonce
string
A nonce that will be set on each style tag that emotion inserts for Content Security Policies.
stylisPlugins
Function
| Array<Function>
A Stylis plugin or plugins that will be run by Stylis during preprocessing. Read the Stylis docs to find out more. This can be used for many purposes such as RTL.
prefix
boolean
| Function
, defaults to true
Allows changing Stylis's vendor prefixing settings. It can be a boolean or a function to dynamically set which properties are prefixed. More information can be found in the Stylis docs.
key
string
, defaults to "css"
The prefix before class names. It will also be set as the value of the data-emotion
attribute on the style tags that emotion inserts and it's used in the attribute name that marks style elements in renderStylesToString
and renderStylesToNodeStream
. This is required if using multiple emotion caches in the same app.
container
HTMLElement
A DOM node that emotion will insert all of its style tags into. This is useful for inserting styles into iframes.
FAQs
emotion's cache
The npm package @emotion/cache receives a total of 9,318,763 weekly downloads. As such, @emotion/cache popularity was classified as popular.
We found that @emotion/cache demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.